package com.didispace.controller;

import com.didispace.domain.User;
import com.didispace.service.UserService;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "users")
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping(value = "/",method = RequestMethod.POST)
    public String postUser(@ModelAttribute User user) {
        userService.create(user.getName(),user.getAge());
        return "success";
    }

    @RequestMapping(value = "/{name}",method = RequestMethod.GET)
    public User getUserByName(@PathVariable(value="name") String name) {
        return userService.findUser(name);
    }
}
